/**
 * 
 */
package com.hera.process.web.primefaces.controller;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.apache.commons.lang.StringEscapeUtils;
//import org.apache.commons.lang.StringEscapeUtils;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;
import org.springframework.stereotype.Service;

/**
 * @author cmontes
 *
 */
@ManagedBean
@ViewScoped
@Service
public class NotifyView implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final static String CHANNEL = "/inbox/";
    
    private String summary;
     
    private String detail;
     
    public String getSummary() {
        return summary;
    }
    public void setSummary(String summary) {
        this.summary = summary;
    }
     
    public String getDetail() {
        return detail;
    }
    public void setDetail(String detail) {
        this.detail = detail;
    }
     
    public void send() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        //
        //eventBus.publish(CHANNEL, new FacesMessage(summary, detail));
        summary = "titulitooo";
        detail = "detalloteeeee";
        System.out.println("enviando notificacion....");
        //eventBus.publish(CHANNEL, new FacesMessage("titulo", "detalle...."));
        //eventBus.publish(CHANNEL + "*", new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
        eventBus.publish("/inbox/u00001", new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
    }
    
    public void send(String strUser) {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        //
        //eventBus.publish(CHANNEL, new FacesMessage(summary, detail));
        summary = "titulo";
        detail = "detalle";
        System.out.println("enviando notificacion al usuario " + strUser);
        //eventBus.publish(CHANNEL, new FacesMessage("titulo", "detalle...."));
        //eventBus.publish(CHANNEL + "*", new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
        eventBus.publish(CHANNEL+strUser, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
    }

}
